import 'package:demo/constants/event_bus_key.dart';
import 'package:demo/model/bean/event/page_destroy_bean.dart';
import 'package:demo/utils/event_bus.dart';
import 'package:flutter/widgets.dart';

class AppRouterObserver extends NavigatorObserver {
  @override
  void didPop(Route route, Route? previousRoute) {
    final String? routeName = route.settings.name;
    if (routeName != null) {
      EventBus.instance.post<PageDestroyBean>(EVENT_BUS_PAGE_DESTROY_KEY, PageDestroyBean(routeName));
    }
  }

  @override
  void didPush(Route route, Route? previousRoute) {}

  @override
  void didRemove(Route route, Route? previousRoute) {}

  @override
  void didReplace({Route? newRoute, Route? oldRoute}) {}

  @override
  void didStartUserGesture(Route route, Route? previousRoute) {}

  @override
  void didStopUserGesture() {}
}
